// BasicFish.cpp: implementation of the CBasicFish class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "BasicFish.h"
#include <cmath>

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CBasicFish::CBasicFish()
{

}

CBasicFish::~CBasicFish()
{

}


//DEL void CBasicFish::DrawToBk(int fx, int fy, IplImage *fishImage, IplImage *bkImage, BOOL isLive)
//DEL {
//DEL 	if (fishImage!=0 && bkImage!=0 && isLive==true)
//DEL 	{
//DEL 		for (int i = 0; i < fishImage->height; i++)
//DEL 		{
//DEL 			for (int j = 0; j < fishImage->width; j++)
//DEL 			{
//DEL 				CV_IMAGE_ELEM(bkImage,UCHAR,fy + i,(fx + j)*3+0)
//DEL 					=CV_IMAGE_ELEM(fishImage,UCHAR,i,j*3+0);
//DEL 				CV_IMAGE_ELEM(bkImage,UCHAR,fy + i,(fx + j)*3+1)
//DEL 					=CV_IMAGE_ELEM(fishImage,UCHAR,i,j*3+1);
//DEL 				CV_IMAGE_ELEM(bkImage,UCHAR,fy + i,(fx + j)*3+2)
//DEL 					=CV_IMAGE_ELEM(fishImage,UCHAR,i,j*3+2);
//DEL 			}
//DEL 		}
//DEL 	}
//DEL }


//DEL void CBasicFish::MoveFish(int &fx, int &fvx, IplImage *fishImage)
//DEL {
//DEL 	fx=fx+fvx;
//DEL 	if (fx <0 || fx > 640)
//DEL 	{
//DEL  		fvx=-fvx;
//DEL 		cvFlip(fishImage,NULL,1);
//DEL  	}
//DEL }

//DEL void CBasicFish::DrawBToBK(IplImage *bkimg)
//DEL {
//DEL 	if (m_aiFishImg!=0 && bkimg!=0 && IsAiLive==true)
//DEL 	{
//DEL 		for (int i = 0; i < m_aiFishImg->height; i++)
//DEL 		{
//DEL 			for (int j = 0; j < m_aiFishImg->width; j++)
//DEL 			{
//DEL 				CV_IMAGE_ELEM(bkimg,UCHAR,m_aiy + i,(m_aix + j)*3+0)
//DEL 					=CV_IMAGE_ELEM(m_aiFishImg,UCHAR,i,j*3+0);
//DEL 				CV_IMAGE_ELEM(bkimg,UCHAR,m_aiy + i,(m_aix + j)*3+1)
//DEL 					=CV_IMAGE_ELEM(m_aiFishImg,UCHAR,i,j*3+1);
//DEL 				CV_IMAGE_ELEM(bkimg,UCHAR,m_aiy + i,(m_aix + j)*3+2)
//DEL 					=CV_IMAGE_ELEM(m_aiFishImg,UCHAR,i,j*3+2);
//DEL 			}
//DEL 		}
//DEL 	}
//DEL }

void CBasicFish::MoveAiFish()
{
	m_aix=m_aix+m_aivx;
	if (m_aix <0 || m_aix > 900)
	{
		m_aivx=-m_aivx;
		cvFlip(m_aiFishImg,NULL,1);
 	}
}

void CBasicFish::DrawToBK(IplImage *bkimg)
{
	if (m_aiFishImg!=0 && bkimg!=0 && IsAiLive==true)
 	{
		for (int i = 0; i < m_aiFishImg->height; i++)
		{
			for (int j = 0; j < m_aiFishImg->width; j++)
			{
				CV_IMAGE_ELEM(bkimg,UCHAR,m_aiy + i,(m_aix + j)*3+0)
					=CV_IMAGE_ELEM(m_aiFishImg,UCHAR,i,j*3+0);
				CV_IMAGE_ELEM(bkimg,UCHAR,m_aiy + i,(m_aix + j)*3+1)
				=CV_IMAGE_ELEM(m_aiFishImg,UCHAR,i,j*3+1);
				CV_IMAGE_ELEM(bkimg,UCHAR,m_aiy + i,(m_aix + j)*3+2)
					=CV_IMAGE_ELEM(m_aiFishImg,UCHAR,i,j*3+2);
 			}
 		}
	}
}
